#define MIN(a,b) ((a<b)?a:b)

int cmp (const int *a, const int *b)
{
    return (*b - *a);
}

int minimumDifference(int* nums, int numsSize, int k){
    qsort(nums, numsSize, sizeof(int), cmp);
    
    if (numsSize == 1)
    {
        return 0;
    }
    int ans = 2147483647;
    for (int i = 0 ; i + k - 1 < numsSize; i++)
    {
        ans = MIN(ans, nums[i] - nums[i + k - 1]);
    }
    return ans;
}